﻿using CoachingOrganizer.Logic.Common;
using CoachingOrganizer.Logic.Models.Tools.MoneyCalculation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoachingOrganizer.Logic.Logic.Tools.MoneyCalculation
{
    internal class MoneyFlowItemNameSuggestionLogic
    {
        private readonly MoneyFlowItemNameSuggestionModel _model;
        private readonly LogicExtender _logicExtender;
        private readonly MoneyFlowLogic _upperLogic;

        public MoneyFlowItemNameSuggestionModel Model
        {
            get { return _model; }
        }

        public int Frequency
        {
            get { return _model.Frequency; }
            set { _model.Frequency = value; }
        }

        public MoneyFlowItemNameSuggestionLogic(MoneyFlowItemNameSuggestionModel model, LogicExtender logicExtender, MoneyFlowLogic upperLogic)
        {
            _model = model;
            _logicExtender = logicExtender;
            _upperLogic = upperLogic;
        }

        public MoneyFlowItemNameSuggestionLogic(LogicExtender logicExtender, MoneyFlowLogic upperLogic, string suggestedName, bool forStableItems)
            : this(new MoneyFlowItemNameSuggestionModel(suggestedName, forStableItems), logicExtender, upperLogic)
        {
            _model.ActivateSuggestionDelegate = ActivateSuggestion;
        }

        public decimal GetOccasionalItemsAmount()
        {
            if (!_model.ForStableItems)
                _upperLogic.OccasionalItems.Select(i => i.Model.Amount).Sum();
            return default(decimal);
        }

        private void ActivateSuggestion()
        {
            if (_model.ForStableItems)
                _upperLogic.Model.NewStableMoneyFlowItemName = _model.SuggestedName;
            else
                _upperLogic.Model.NewOccasionalMoneyFlowItemName = _model.SuggestedName;
        }
    }
}
